<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { equipApi } from '@/api/controller'
  import updateForm from './updateForm.vue';
  import updateStatus from './updateStatus.vue';
  import { Toastloading } from '@/utils/public';
  const updateFormRef = ref(),
  updateStatusRef = ref()
  const action = reactive({
    list:[] as Array<any>
  })
  const statusChange = (row:any)=>{
    updateFormRef.value.openDialog(row)
  }
  const handleUpdate = (row:any)=>{
    updateStatusRef.value.openDialog(row)
  }
  
  const filtersType = (type:number = 0)=>{
    return ['关闭','开启'][type]
  }
  const getList = async()=>{
    const loading = Toastloading()
    const res = await equipApi.gameSwitch()
    loading.close()
    const { data=[] } = res || {}
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="120" prop="game_name" label="游戏类型" />
      <el-table-column min-width="140" prop="if_screen" label="飘屏公告状态">
        <template #default="scope">{{ filtersType(scope.row.if_screen) }}</template>
      </el-table-column>
      <el-table-column min-width="140" prop="if_new_protect" label="新人保护状态">
        <template #default="scope">{{ filtersType(scope.row.if_new_protect) }}</template>
      </el-table-column>
      <el-table-column min-width="180" prop="new_protect_num" label="新用户保护次数" />
      <el-table-column min-width="140" prop="if_day_protect" label="每日保护状态">
        <template #default="scope">{{ filtersType(scope.row.if_day_protect) }}</template>
      </el-table-column>
      <el-table-column min-width="180" prop="day_num_1" label="每日保护次数1" />
      <el-table-column min-width="180" prop="day_num_2" label="每日保护次数2" />
      <el-table-column min-width="140" prop="if_white" label="白名单功能状态">
        <template #default="scope">{{ filtersType(scope.row.if_white) }}</template>
      </el-table-column>
      <el-table-column min-width="180" prop="no_protect_num" label="大户额度" />
      <el-table-column min-width="180" prop="price" label="单次价格" />
      <el-table-column min-width="200" prop="if_float" label="浮动概率开关">
        <template #default="scope">{{ filtersType(scope.row.if_float) }}</template>
      </el-table-column>
      <el-table-column min-width="180" label="浮动概率利润阀值">
        <template #default="scope">
          {{ scope.row.float_min }}% ~ {{ scope.row.float_max }}%
        </template>
      </el-table-column>
      <el-table-column width="220" fixed="right" label="操作">
        <template #default="scope">
          <el-button type="primary" @click="statusChange(scope.row)">更新配置</el-button>
          <el-button type="primary" @click="handleUpdate(scope.row)">游戏状态</el-button>
        </template>
      </el-table-column>
    </el-table>
    <updateForm ref="updateFormRef" @update-list="getList" />
    <updateStatus ref="updateStatusRef" @update-list="getList" />
  </div>
</template>

<style lang='scss' scoped>
  
</style>